<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP '分类' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="<%=basePath%>/javascript/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="<%=basePath%>/javascript/MQuery.js"></script>
	<script type="text/javascript" src="<%=basePath%>/javascript/jquery.ztree-2.6.min.js"></script>
	<link rel="stylesheet" href="<%=basePath%>/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript">
	
	var zTree;
	var setting = {
		isSimpleData: false,
		treeNodeKey: "id",
		nodesCol : "children",
		showLine: true,
		root:{ 
			isRoot:true,
			children:[]
		}
	};
	
	var url = "<%=basePath%>/servlet/InventoryClassServlet";
	$(document).ready(function(){
		MQuery.url = url;
		MQuery.data.forward = "listJqueryTreeData";
		MQuery.data.random = Math.random();
		MQuery.responseFun = addSuccess;
		MQuery.submit();
		
	
	});
	
	function addSuccess(data){
		setting.expandSpeed = ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast";
		zTree = $("#tree").zTree(setting, data);
	}


	function clickButton(){
		if(zTree.getSelectedNode().binvCend==1){//如果选择的是最后一级
			alert(zTree.getSelectedNode().id+" | "+zTree.getSelectedNode().name);
		}
	}
	
	function addInventoryClass(){
		if(!zTree||!zTree.getSelectedNode()){
			alert("请选择要添加的节点");
			return;
		}
		
		
		MQuery.url = url;
		MQuery.data.forward = "add";
		MQuery.data.random = Math.random();
		MQuery.data.parentCinvCcode = zTree.getSelectedNode().id;//父节点编号
		MQuery.data.cinvCcode = $('#CinvCcode').val();//编号 顶级为01-99 二级为 001-999 三级为001-999
		MQuery.data.cinvCname = $('#CinvCname').val();//名称
		MQuery.data.iinvCgrade = $('#IinvCgrade').val();//级别 顶级为1 二级为2 三级为3 ,不能添加4级
		
		MQuery.responseFun = addinvResponse;
		MQuery.submit();
		
		function addinvResponse(json){
			alert("添加成功");
		}
	}
	
	
	</script>
  </head>
  
  <body>
    <li></input> &nbsp; <input type="button" onclick="clickButton()" value="打印" >
    
    <h1>Simple Tree example参考:</h1><a href="http://www.baby666.cn/hunter/zTree.html" target="_blank">http://www.baby666.cn/hunter/zTree.html</a>
	<ul id="tree" class="tree" style="width:230px; overflow:auto;"></ul>
	<label>*分类号(顶级为01-99 二级为 001-999 三级为001-999)</label><br><input id="CinvCcode" type="text" ><br>
	<label>*名称</label><br><input id="CinvCname" type="text" ><br>
	<label>*IinvCgrade 级别(顶级为1 二级为2 三级为3 ,不能添加4级)</label><br><input id="IinvCgrade" type="text" ><br>
	<li><input type="button" value="添加分类" onclick="addInventoryClass()"/><br>
  </body>
</html>
